package com.fr.lintcode;

import org.junit.Test;

public class Q1365 {
    /**
     * @param array:
     *            an integer array
     * @return: the length of the minimum cycle section
     */
    public int minimumCycleSection(int[] array) {
        // Write your code here
        if (array == null) {
            return 0;
        }
        int min = array.length;
        for (int i = 1; i < min; i++) {
            if (check(array, i)) {
                return i;
            }
        }
        return min;
    }

    private boolean check(int[] array, int interval) {
        for (int i = 0; i < interval; i++) {
            int value = array[i];
            for (int j = i + interval; j < array.length; j = j + interval) {
                if (value != array[j]) {
                    return false;
                }
            }
        }
        return true;
    }

    @Test
    public void testA() {
        int[] array = {1, 2, 1, 2, 1, 4};
        int min = minimumCycleSection(array);
        System.out.println(min);
    }
}
